Lost context for Realized dialog

I've made a rather startling discovery: there seems to be a loss of DXL context for a 'realized' dialog that is not then 'show'n, when the DXL ends naturally (running out of code to execute) and doesn't end explicitely. Read and run the code below. Selecting the 1st 4 options (that explicitely end the DXL) allow the realized dialog to work correctly, but the last option (allowing the code to run out of things to do) causes the realized dialog to lose its DXL context resulting in "undefined" global variable access.

So far I see that 'explicit endings' of DXL are <1> halt() <2> show() <3> error() <4> generating a DXL error.

A curious symptom here is that noError/lastError do not trap this sort of error, code stops even when there is a previous noError, but then you get no notification of the error at all.

This discovery means my statement of a couple weeks ago that there is a big difference between "realize" and "show" is probably wrong; that demo code no doubt ended naturally causing the errors. It appears that it could be true that "show" is just a "realize" and "halt". That seems to be the case with the single big dialog I practiced with which worked with a realize/halt sequence. Will need to study that a little more.

I did demonstrate that once a dialog is 'realized' you cannot add or move elements around, even if you first 'hide' it; you need to destroy and start again.
 

  • Louie
// Special Ending
/*    This DXL demonstrates the corruption of the DXL context for 'realized' but not 'shown' dialogs.
                When a DXL 'realizes' a dialog and then the execution ends because it runs out of lines
                of code, and doesn't end because of some explicit event, then any 'realized'
                dialog remains shown but is stripped of its context, and any global variables
                it accesses generates "unassigned variable reference" errors.
        An 'event' seems to be any of these:
                halt
                show(dialog)
                error(message)
                generating a DXL error
                        Note that a 'block' command doesn't end the execution.
        Run this code.  If you choose any of the 1st 4 options and then use the [Increment] button on
                the realized dialog, it works.  But if you choose the last option (nothing), that
                button generates unassigned variable errors, even though its accesses a defined global variable.

        I find it curious that noError/lastError do NOT trap this sort of error; code stops executing at the
                offending line (i++ below), but noError() prevents it from being displayed in the DXL window

        I'm not sure what to think about this.  I guess we need more experiments on the difference between
                a 'realized' and a 'shown' dialog, if indeed there are any differences.
*/
DB      db
int     i = 0
 
//****************
void    SpecialEnding()
{     // Prompt user to make a Special Ending to the DXL, if any.
        // Special ending is halt, error, or generating a run-time DXL error
        string  Options[] = {
                "Show Sub-Dialog",
                "Do 'Halt'?",
                "Do 'Error'?",
                "Generate DXL Error?",
                "Nothing. This causes increment error"
                                }
        int     i
        int     Choice = query("End DXL with special..", Options)
        if    (Choice == 0) {print "Special Ending: show(db)\n";DB dbT = create(db, "Close Me");label(dbT, "Close this Dialog");show(dbT)}
        elseif(Choice == 1) {print "Special Ending: halt\n"; halt}
        elseif(Choice == 2) {print "Special Ending: error()\n"; error("End By 'error()'")}
        elseif(Choice == 3) {print "Special Ending: i++\n"; Object o=null; Module m = module(o)}        // Generate "null Object.." error
        else                      {print "Special Ending: None\n"}                      // No special ending
}    // end SpecialEnding()
 
 
void    applyIncrement(DB dbXX)
{    lastError()                     // Offset the noError() below
        print "Incrementing....\t"
        i++
        print ("Increment OK...\t")
}
//****************
void    applyNoError(DB dbXX)
{    noError()                       // Attempt to trap the error
        i++                             
        string ErrMess = lastError()
        if (!null ErrMess) //
        then warningBox(ErrMess)        // This line never runs because an error halts the DXL and is not trapped.
        else print ("Increment OK...\t")
}    // end applyNoError()
 
//****************
void    BuildDialog()
{    db      = centered("Special Ending")
        apply(db, "Increment global variable", applyIncrement)
        apply(db, "Increment, with noError()", applyNoError)
 
        realize(db)             // realized, not shown
}
//      **** MAIN ****
BuildDialog()
SpecialEnding()

llandale - Wed Oct 26 10:07:14 EDT 2011